﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_CatgeDict : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainDataDict_MainDataCatge_DataCatgeId",
                table: "MainDataDict");

            migrationBuilder.DropTable(
                name: "MainDataCatge");

            migrationBuilder.CreateTable(
                name: "MainCatgeDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    CatgeCodg = table.Column<string>(type: "text", nullable: false),
                    CatgeName = table.Column<string>(type: "text", nullable: false),
                    TypeCode = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    IsDefault = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainCatgeDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainCatgeDict_MainCatgeDict_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainCatgeDict",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainCatgeDict_ParentId",
                table: "MainCatgeDict",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataDict_MainCatgeDict_DataCatgeId",
                table: "MainDataDict",
                column: "DataCatgeId",
                principalTable: "MainCatgeDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainDataDict_MainCatgeDict_DataCatgeId",
                table: "MainDataDict");

            migrationBuilder.DropTable(
                name: "MainCatgeDict");

            migrationBuilder.CreateTable(
                name: "MainDataCatge",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    CatgeCodg = table.Column<string>(type: "text", nullable: false),
                    CatgeName = table.Column<string>(type: "text", nullable: false),
                    IsDefault = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    TypeCode = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainDataCatge", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainDataCatge_MainDataCatge_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainDataCatge",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainDataCatge_ParentId",
                table: "MainDataCatge",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataDict_MainDataCatge_DataCatgeId",
                table: "MainDataDict",
                column: "DataCatgeId",
                principalTable: "MainDataCatge",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
